# @Time : 2020/6/6 0006 15:34
# @Author : XYBH
# @Version：V 0.1
# @File : fourchart.py.py
# @desc :

import pandas as pd
import matplotlib.pyplot as plt
import pylab as pl
import numpy as np

from drawcharts import dateRange

# 意大利，伊朗，俄罗斯，中国

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
data = pd.read_excel('csv/OneDay/China_OneDay.xlsx',
                     usecols=['国家', '确诊人数', '治愈人数', '死亡人数', '更新时间'])


confirm_count = []
cured_count = []
dead_count = []
add = []
time = []
for i in range(0, data.values.shape[0]):
    if i != 0:
        add.append(data.values[i - 1][1] - data.values[i][1])
    else:
        add.append(0)
    confirm_count.append(data.values[i][1] - data.values[i][2] - data.values[i][3])
    cured_count.append(data.values[i][2])
    dead_count.append(data.values[i][3])
    time.append(data.values[i][4])

confirm_count.reverse()
cured_count.reverse()
dead_count.reverse()
add.reverse()
time.reverse()

date_str = []
if data.values[0][0] == '涓浗':
    for d in time:
        d = '0'+str(d)
        print(d)
        d = d[0:2]+'-'+d[2:]
        print(d)
        date_str.append(d)
else:
    for d in time:
        d = str(d).split("-")[1] + "-" + str(d).split("-")[2]
        d = d.split(' ')[0]
        date_str.append(d)

fig = plt.figure()
ax1 = fig.add_subplot(111)
plt.bar(date_str, add, alpha=0.3, linewidth=10, color='blue', label=u'新增人数')

# 子图
ax2 = ax1.twinx()  # this is the important function
ax2.plot(date_str, confirm_count, linewidth=2, label=u'现存确诊人数', color='red')
ax2.plot(date_str, cured_count, linewidth=2, label=u'治愈人数', color='green')
ax2.plot(date_str, dead_count, linewidth=2, label=u'死亡人数', color='orange')

# y轴坐标范围
ax2.set_ylim([0, max(max(confirm_count), max(cured_count), max(dead_count)) * 1.1])
ax1.set_ylim([0, 50000 * 1.1])

# 图例位置
ax1.legend(loc=1)
ax2.legend(loc=2)

# y轴标签
ax1.set_ylabel('人数(人)')
ax2.set_ylabel('人数(人)')


plt.xticks(date_str[::13], rotation=45)
plt.show()
